var cache = {},
		lastXhr;

/**
 * obj autocomplete的对象
 * url ajax的网址
 * convert 转换url获取的json数据函数
 * select 选择搜索项后的操作函数
 *
 */
function autocomplete(obj, url, convert, selectFunc)
{
	obj.autocomplete({
		minLength: 1,
		select: function(event, ui) {
			selectFunc(event, ui, this);
		},
		source: function( request, response ) {
			var term = request.term;
			var cacheKey = $(this).attr('element').attr('class') + '.' + term;
			
			if ( cacheKey in cache ) {
				response( cache[ cacheKey ] );
				return;
			}
			//alert(encodeURI(term));
			lastXhr =$.ajax({
					url:url,
					dataType:"text",
					data:'keyword='+encodeURI(encodeURI(term)),
					success:function(data){
							var text = [];
							var datas = data.split(",");
							
							for(var i=0;i<datas.length;i++)
							{
								text.push(datas[i]);
							}
							//alert(text);
							response(text);
					}
					
				});
			/*lastXhr = $.getJSON(url+'?keyword='+encodeURIComponent(term), function( data, status, xhr ) {
				alert(xhr);
				data = convert(data);
				cache[ cacheKey ] = data;
				if ( xhr === lastXhr ) {
					response( data );
				}
			});*/
		}
	});
}

// 默认转换jquery autocomplete自动完成获取的数据
function convertData(data)
{
	//alert(data);
	if ( data.status == 0 )
	{
		data = [{"label":data.info,"value":""}];
	}
	else
	{
		data = data.data;
	}
	
	return data;
}

function ajaxShanchu(obj)
{
	if ( ! confirm($(obj).attr('title')) )
	{
		return false;
	}

	$.getJSON(obj.href, function (data){
		//alert(data.info);
		if ( data.status == 1 )
		{
			$(obj).parent().remove();
		}		
	});
}

/**
 * 所有的提交按钮都变成圆角
 *
 */
function buttonCorner()
{
	//$('input:button,input:submit').corner('4px');
	$('input:button,input:submit').addClass('input_c');
}

// 按钮都变圆角
$(function (){
	buttonCorner();
});

/**
 * 日期控件中文配置
 */
$(function($){
	$.datepicker.regional['zh-CN'] = {
		closeText: '关闭',
		prevText: '&#x3c;上月',
		nextText: '下月&#x3e;',
		currentText: '今天',
		monthNames: ['一月','二月','三月','四月','五月','六月',
		'七月','八月','九月','十月','十一月','十二月'],
		monthNamesShort: ['一','二','三','四','五','六',
		'七','八','九','十','十一','十二'],
		dayNames: ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'],
		dayNamesShort: ['周日','周一','周二','周三','周四','周五','周六'],
		dayNamesMin: ['日','一','二','三','四','五','六'],
		weekHeader: '周',
		dateFormat: 'yy-mm-dd',
		firstDay: 1,
		isRTL: false,
		showMonthAfterYear: true,
		yearSuffix: '年'};
	$.datepicker.setDefaults($.datepicker.regional['zh-CN']);
});


function resetForm(form)
{
	$(form).find(':input').not(':submit,:button').val(null);
}